<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>设置点标注的文本标签</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <script src="http://webapi.amap.com/maps?v=1.3&key=e51bd3d35de6fe57218feaa7e579481f "></script>
    
    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
    <link rel="stylesheet" href="../../css/mui.min.css">
    <script src="../../js/getURLParam.js"></script>
	<script src="../../js/mui.min.js"></script>
</head>
<body>
	<div id="test" class="tip" style="margin-top: 0px;width:100%;height: 34px;">
	<button onclick="toon()" style="float: left;width:50%;">开机</button>
	<button onclick="tooff()" style="float: right;width:50%;">关机</button>
</div>
<div style="margin-top: 34px;width:100%;height: auto;" id="container"></div>

<div id="tip" class="tip" style="float: left;margin-top: 150px;right: 10px;display: none;" ></div>
<script>
			var sessionid=GetQueryString("sessionid");
	        var proVersion =GetQueryString("proVersion");
	        var accountid="216";
	        var vclId="";
	        var keySta ="2";
	        var vclNum="";
			var lng ="";
			var lat ="";
			var posTime ="";
			var vclSpd ="";
			var vclDrct="";
    var map = new AMap.Map('container', {
        resizeEnable: true,
        center: [116.397428, 39.90923],
        zoom: 5
    });
    function getBeforeDate(n) {
				var n = n;
				var d = new Date();
				var year = d.getFullYear();
				var mon = d.getMonth() + 1;
				var day = d.getDate();
				if (day <= n) {
					if (mon > 1) {
						mon = mon - 1;
					} else {
						year = year - 1;
						mon = 12;
					}
				}
				d.setDate(d.getDate() - n);
				year = d.getFullYear();
			
				mon = d.getMonth() + 1;
			
				day = d.getDate();
				s = year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day);
				return s;
			}
    function toon(){
	        vclId="";
    		keySta = "1";
    		getautoMap();
    }
    function tooff(){
    	 vclId="";
    	keySta = "0";
    	getautoMap();
    }
    var vclmsgarr=new Array();
    var _onClick = function(e){
    	var id=e.target.getExtData( );
    	var tocontent=vclmsgarr[id];
    	 var vcltest=new Array()[5];
    	 vcltest=tocontent.split(",");
    	//alert(vcltest[0],vcltest[1],vcltest[2],vcltest[3],vcltest[4]);经度，纬度，设备号，时间，车速，设备id
    	var lnglat = new AMap.LngLat(lng,lat);
    	 vclId=vcltest[5];
    	document.getElementById("tip").style.display="";
    	document.getElementById("tip").innerHTML=vcltest[2] +"<button onclick='gotoclose()'>关闭</button>"+
    		"<br/>时间："+vcltest[3]+"<br/>车速："+vcltest[4]+
    		"<br/><button onclick='gotoguiji(this)'>轨迹</button>"
    		+"<button onclick='gotosinglevclfile(this)'>单车信息</button><br/>"
    }
    getautoMap();
			function getautoMap(){
				mui.ajax('../../../APP/vclMapList',{          
				data:{param:'{"proVersion":"'+proVersion+'","accountId":"'+accountid+'","sessionid":"'+sessionid+'","data":{"vclId":"'+vclId+'","keySta":"'+keySta+'"}}'},
				dataType:'jsonp',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:1000000,//超时时间设置为10秒；
				
				success:function(data){
					var jsonObj = window.JSON.parse(data);
						var resultdata = jsonObj.data;
					if(jsonObj.resultCode=="1"){
					if(vclId!=null&&vclId!=""){//单设备
							lng=resultdata[0].lng;
							lat=resultdata[0].lat;
							keySta=resultdata[0].keysta;
							vclNum=resultdata[0].vclnum;
							posTime=resultdata[0].postime;
							vclSpd=resultdata[0].vclspd;
							var marker = new AMap.Marker({
						    	icon:'../../images/drawable-hdpi/arrow_greennew.png',
						    	//icon:myIcon,
						        position: [lng,lat]
						    });
						     marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
        					//offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
       						 content: vclNum
    						});
						    if(keySta=="1"){//开机
								marker.setIcon("../../images/drawable-hdpi/arrow_greennew.png");
							}else{
								marker.setIcon("../../images/drawable-hdpi/arrow_rednew.png");
							}
						    marker.setMap(map);
							
							
							 marker.on('click', function() {
       	 						var lnglat = new AMap.LngLat(lng,lat);
    							map.setCenter(marker.getPosition());
    							document.getElementById("tip").style.display="";
    							document.getElementById("tip").innerHTML=vclNum +"<button onclick='gotoclose()'>关闭</button>"+
    							"<br/>时间："+posTime+"<br/>车速："+vclSpd+
    							"<br/><button onclick='gotoguiji()'>轨迹</button>"
    							+"<button onclick='gotosinglevclfile()'>单车信息</button><br/>"
    							;
    						});
    						
						}else {//多设备
							 var map = new AMap.Map('container', {
       						 resizeEnable: true,
        					center: [116.397428, 39.90923],
       						 zoom: 5
    						});
							for(var i=0;i<resultdata.length;i++){
								lng=resultdata[i].lng;
								lat=resultdata[i].lat;
								keySta=resultdata[i].keysta;
								vclNum=resultdata[i].vclnum;
								vclId=resultdata[i].vclid;
								posTime=resultdata[i].postime;
								vclSpd=resultdata[i].vclspd;
								vclmsgarr[i]=lng+","+lat+","+vclNum+","+posTime+","+vclSpd+","+vclId;
								var marker = new AMap.Marker({
							    	icon:'../../images/drawable-hdpi/arrow_greennew.png',
							        position: [lng,lat],
							        extData:i
							    });
						    if(keySta=="1"){//开机
								marker.setIcon("../../images/drawable-hdpi/arrow_greennew.png");
							}else{
								marker.setIcon("../../images/drawable-hdpi/arrow_rednew.png");
							}
							 marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
        					offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
       						 content: vclNum
    						});
						    marker.setMap(map);
							AMap.event.addListener(marker, 'click', _onClick);
							}
						}
					}else{
					}
					
				},error: function(xhr, type, errorThrown) {
						}
			});
		}
		/*marker.on('click', function() {
       	 						var lnglat = new AMap.LngLat(lng,lat);
    							document.getElementById("tip").style.display="";
    							document.getElementById("tip").innerHTML=vclNum +"<button onclick='gotoclose()'>关闭</button>"+
    							"<br/>时间："+posTime+"<br/>车速："+vclSpd+
    							"<br/><button onclick='gotoguiji()'>轨迹</button>"
    							+"<button onclick='gotosinglevclfile()'>单车信息</button><br/>"
    							;
    						});*/
	function gotoguiji(){//轨迹
		var  nowtime=getBeforeDate(0);
    	window.parent.location.href="vcltrack.html?sessionid="+sessionid+"&proVersion="+proVersion+"&accountId="+accountid+"&vclId="+vclId+"&bgnTime="+nowtime+"&endTime="+nowtime;
    	mui.toast(vclId);
	}
    function gotosinglevclfile(){//单车信息
    	window.parent.location.href="../singfile/singlevclfile.html?sessionid="+sessionid+"&proVersion="+proVersion+"&accountId="+accountid+"&vclid="+vclId;
    }
    function gotoclose(){
    	document.getElementById("tip").style.display="none";
    }
  
</script>
</body>
</html>